<html>
<head><meta charset="utf-8"><title>miri &quot;trying to reborrow for Unique&quot; · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html">miri &quot;trying to reborrow for Unique&quot;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="188614302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188614302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188614302">(Feb 20 2020 at 06:53)</a>:</h4>
<p>Hi. When running <code>cargo miri test</code> on my library I get <code>error: Miri evaluation error: trying to reborrow for Unique, but parent tag &lt;160163&gt; does not have an appropriate item in the borrow stack</code> but I don’t see how to find the root cause. The full output is at <a href="https://paste.mozilla.org/iVboPkXU" target="_blank" title="https://paste.mozilla.org/iVboPkXU">https://paste.mozilla.org/iVboPkXU</a>, the code at <a href="https://github.com/servo/html5ever/tree/304c155bce19f956f0641cce3a1e19bc3b7bdaa1/zbuf" target="_blank" title="https://github.com/servo/html5ever/tree/304c155bce19f956f0641cce3a1e19bc3b7bdaa1/zbuf">https://github.com/servo/html5ever/tree/304c155bce19f956f0641cce3a1e19bc3b7bdaa1/zbuf</a>.</p>



<a name="188614450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188614450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188614450">(Feb 20 2020 at 06:57)</a>:</h4>
<p>The error happens when trying to take <code>&amp;mut</code> reference to something inside of a heap allocation made through <code>std::alloc::alloc</code>. The struct that contains the <code>ptr::NonNull</code> is created on the stack with <code>let mut</code> and then used with methods that take <code>&amp;mut self</code></p>



<a name="188614510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188614510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188614510">(Feb 20 2020 at 06:59)</a>:</h4>
<p>(Also, “reborrow for Unique” means <code>&amp;mut</code> not <code>std::ptr::Unique</code>, right?)</p>



<a name="188620128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188620128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188620128">(Feb 20 2020 at 09:02)</a>:</h4>
<p>Try passing <code>-Zmiri-track-pointer-tag=160163</code> to track where it is invalidated.</p>



<a name="188620142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188620142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188620142">(Feb 20 2020 at 09:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219747">Simon Sapin</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22/near/188614510" title="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22/near/188614510">said</a>:</p>
<blockquote>
<p>(Also, “reborrow for Unique” means <code>&amp;mut</code> not <code>std::ptr::Unique</code>, right?)</p>
</blockquote>
<p>Yes</p>



<a name="188625027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188625027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188625027">(Feb 20 2020 at 10:12)</a>:</h4>
<p>The output looks the same with <code>cargo +nightly miri test -- -Zmiri-track-pointer-tag=160163</code>. Or is it a <code>RUSTFLAGS</code>?</p>



<a name="188633537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188633537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188633537">(Feb 20 2020 at 12:44)</a>:</h4>
<p>I don't know. You can try using a RUSTFLAG.</p>



<a name="188634638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188634638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188634638">(Feb 20 2020 at 12:59)</a>:</h4>
<p><code>error: unknown debugging option: `miri-track-pointer-tag` </code> with <code>RUSTFLAGS</code></p>



<a name="188635940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188635940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188635940">(Feb 20 2020 at 13:19)</a>:</h4>
<p>“<code>-Zmiri-track-pointer-tag=&lt;tag&gt;</code> aborts interpretation with a backtrace when the given pointer tag is popped from a borrow stack (which is where the tag becomes invalid and any future use of it will error anyway).”</p>



<a name="188636033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188636033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188636033">(Feb 20 2020 at 13:20)</a>:</h4>
<p>I’m not sure what that means, but is it possible to get the error above if that tag never was on the borrow stack?</p>



<a name="188644161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188644161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188644161">(Feb 20 2020 at 14:52)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> what is the borrow stack stack? How can I build a mental model of how to write code that manually allocates and deals with raw pointers while making miri happy?</p>



<a name="188681341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681341">(Feb 20 2020 at 21:42)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> a bunch of material about Stacked Borrows is collected at <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md</a></p>



<a name="188681416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681416">(Feb 20 2020 at 21:44)</a>:</h4>
<p>that <code>track-pointer-tag</code> didnt do anything is odd... it should show a "warning" when the ptr tag gets removed (the "abort" part is not true any more)</p>



<a name="188681508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681508">(Feb 20 2020 at 21:44)</a>:</h4>
<p>but indeed it could be that the tag never was on the respective borrow stack</p>



<a name="188681556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681556">(Feb 20 2020 at 21:45)</a>:</h4>
<p>since this is around slices, my first guess would be: did you do <code>&amp;slice[0] as *mut _</code> instead of <code>slice.as_mut_ptr()</code>? the former doesnt work</p>



<a name="188681595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681595">(Feb 20 2020 at 21:45)</a>:</h4>
<p>IOW, it sounds like you are taking a pointer that is okay for some part of the relevant memory, and trying to use it for a larger part of memory. That's why the tag is missing.</p>



<a name="188681737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681737">(Feb 20 2020 at 21:47)</a>:</h4>
<p>Yes I’m using <code>as_mut_ptr</code> but on <code>[MaybeUninit&lt;u8&gt;; 0]</code> which is the last field of a <code>#[repr(C)]</code> struct, in a heap allocation larger than the struct</p>



<a name="188681779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681779">(Feb 20 2020 at 21:47)</a>:</h4>
<p><a href="https://github.com/servo/html5ever/blob/304c155bce19f956f0641cce3a1e19bc3b7bdaa1/zbuf/heap_data.rs#L99-L113" target="_blank" title="https://github.com/servo/html5ever/blob/304c155bce19f956f0641cce3a1e19bc3b7bdaa1/zbuf/heap_data.rs#L99-L113">https://github.com/servo/html5ever/blob/304c155bce19f956f0641cce3a1e19bc3b7bdaa1/zbuf/heap_data.rs#L99-L113</a></p>



<a name="188681873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188681873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188681873">(Feb 20 2020 at 21:47)</a>:</h4>
<p>ah... yeah Stacked Borrows wouldnt be happy about that</p>



<a name="188682002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682002">(Feb 20 2020 at 21:48)</a>:</h4>
<p>as long as its all raw ptrs, it doesnt care</p>



<a name="188682033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682033">(Feb 20 2020 at 21:49)</a>:</h4>
<p>Doesn’t care about what?</p>



<a name="188682091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682091">(Feb 20 2020 at 21:50)</a>:</h4>
<p>anything, really... if you get a raw ptr from the allocator and only ever use raw ptr ops, I dont think it is even possible to get a Stacked Borrows error</p>



<a name="188682097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682097">(Feb 20 2020 at 21:50)</a>:</h4>
<p>but the moment you create a reference, it and every ptr derived from it (including raw ptrs derived from it) is confined to the bounds given by the type of the reference</p>



<a name="188682173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682173">(Feb 20 2020 at 21:50)</a>:</h4>
<p>Hmm I see. I guess what I’d need is field projection for raw pointers</p>



<a name="188682201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682201">(Feb 20 2020 at 21:51)</a>:</h4>
<p>we have that, but only on nightly</p>



<a name="188682207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682207">(Feb 20 2020 at 21:51)</a>:</h4>
<p>Right</p>



<a name="188682211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682211">(Feb 20 2020 at 21:51)</a>:</h4>
<p>on stable, working with only raw ptrs is not possible :/</p>



<a name="188682238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682238">(Feb 20 2020 at 21:51)</a>:</h4>
<p>Well I’d have to manually compute byte offsets, which doesn’t feel great</p>



<a name="188682272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682272">(Feb 20 2020 at 21:51)</a>:</h4>
<p>well or you wait until raw ptrs becomes better</p>



<a name="188682334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682334">(Feb 20 2020 at 21:52)</a>:</h4>
<p>you can still use Miri with <code>-Zmiri-disable-validation</code> (though that disables more than just stacked borrows... we should have a flag just for that)</p>



<a name="188682338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682338">(Feb 20 2020 at 21:52)</a>:</h4>
<p>And <code>size_of::&lt;Header&gt;()</code> is more conservative than needed since it rounds up to a multiple of alignment</p>



<a name="188682388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682388">(Feb 20 2020 at 21:52)</a>:</h4>
<p>not sure what you mean?</p>



<a name="188682414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682414">(Feb 20 2020 at 21:53)</a>:</h4>
<p>the issue tracking this problem is <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/134" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/134">https://github.com/rust-lang/unsafe-code-guidelines/issues/134</a>. if you want to add some information there or briefly describe your usecase, that would be great.</p>



<a name="188682609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682609">(Feb 20 2020 at 21:55)</a>:</h4>
<p>My header is <code>{ Cell&lt;usize&gt;, u32 }</code>, which on 64-bit has size_of == 16 but only 12 useful bytes, so the data could start at the 13th byte</p>



<a name="188682667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682667">(Feb 20 2020 at 21:56)</a>:</h4>
<p>ah</p>



<a name="188682687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682687">(Feb 20 2020 at 21:56)</a>:</h4>
<p>but that would make header references overlap with the data...</p>



<a name="188682768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682768">(Feb 20 2020 at 21:57)</a>:</h4>
<p>Hence ideally having having a DST <code>{ Cell&lt;usize&gt;, u32, [u8] }</code>, but with a thin pointer</p>



<a name="188682832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682832">(Feb 20 2020 at 21:58)</a>:</h4>
<p>is one of the other fields the length of the slice part?</p>



<a name="188682835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682835">(Feb 20 2020 at 21:58)</a>:</h4>
<p><code>{ Cell&lt;usize&gt;, u32, [u8; 0] }</code> was an attempt to approximate that</p>



<a name="188682851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682851">(Feb 20 2020 at 21:58)</a>:</h4>
<p>The <code>u32</code> is the allocated capacity</p>



<a name="188682881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682881">(Feb 20 2020 at 21:58)</a>:</h4>
<p>hm. the interaction of custom DST and Stacked Borrows is... interesting at least ;)</p>



<a name="188682903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682903">(Feb 20 2020 at 21:59)</a>:</h4>
<p>TBH probably the best bet is to just ignore everything except for the fixed-size prefix</p>



<a name="188682936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188682936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188682936">(Feb 20 2020 at 21:59)</a>:</h4>
<p>but that would likely lead to problems similar as yours</p>



<a name="188683034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188683034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188683034">(Feb 20 2020 at 22:00)</a>:</h4>
<p>anyway it's getting late, feel free to add some more questions here but I am going to go to sleep for now :D</p>



<a name="188683040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/188683040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#188683040">(Feb 20 2020 at 22:00)</a>:</h4>
<p>TBH I’m not counting on custom DSTs in the language having even a serious design proposal in the next few years, if ever</p>



<a name="189190831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/189190831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#189190831">(Feb 27 2020 at 06:43)</a>:</h4>
<p>Yeah, I had issues trying to use a <code>[u8; 0]</code> as the start of an allocation offset for a custom-dst-like thing <a href="https://github.com/thomcc/thin_str/blob/master/src/lib.rs#L49" target="_blank" title="https://github.com/thomcc/thin_str/blob/master/src/lib.rs#L49">https://github.com/thomcc/thin_str/blob/master/src/lib.rs#L49</a>. Miri got mat about using the [u8; 0] so now I just use it for some offset sanity checks. Kinda annoying but <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<a name="189197272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/189197272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#189197272">(Feb 27 2020 at 09:14)</a>:</h4>
<p><span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span> could you write a summary somewhere about this? Ideally, a self-contained snippet demonstrating the pattern that you think should work, but which Miri complains about. Once we got a nice demo, it would be good to add that to <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/134" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/134">https://github.com/rust-lang/unsafe-code-guidelines/issues/134</a>.</p>



<a name="189197306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20%22trying%20to%20reborrow%20for%20Unique%22/near/189197306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20.22trying.20to.20reborrow.20for.20Unique.22.html#189197306">(Feb 27 2020 at 09:15)</a>:</h4>
<p><span class="user-mention" data-user-id="219747">@Simon Sapin</span> <code>-Zmiri-disable-stacked-borrows</code> just landed in Miri; with the next submodule update then one (unsatisfying) option is to at least use Miri to test all the other things besides the aliasing rules.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>